package com.agent.platform.service;

import com.agent.platform.entity.AgentInfo;
import com.agent.platform.entity.TaskInfo;
import com.agent.platform.mapper.AgentInfoMapper;
import com.agent.platform.mapper.TaskInfoMapper;
import com.agent.platform.vo.DashboardVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DashboardService {
    
    private final AgentInfoMapper agentInfoMapper;
    private final TaskInfoMapper taskInfoMapper;
    
    public DashboardVO getOverview() {
        DashboardVO vo = new DashboardVO();
        
        // 智能体统计
        vo.setTotalAgents(agentInfoMapper.selectCount(null));
        vo.setOnlineAgents(agentInfoMapper.selectCount(
            new LambdaQueryWrapper<AgentInfo>().eq(AgentInfo::getStatus, "ONLINE")
        ));
        
        // 任务统计
        vo.setTotalTasks(taskInfoMapper.selectCount(null));
        vo.setPendingTasks(taskInfoMapper.selectCount(
            new LambdaQueryWrapper<TaskInfo>().eq(TaskInfo::getStatus, "PENDING")
        ));
        vo.setRunningTasks(taskInfoMapper.selectCount(
            new LambdaQueryWrapper<TaskInfo>().eq(TaskInfo::getStatus, "RUNNING")
        ));
        vo.setSuccessTasks(taskInfoMapper.selectCount(
            new LambdaQueryWrapper<TaskInfo>().eq(TaskInfo::getStatus, "SUCCESS")
        ));
        vo.setFailedTasks(taskInfoMapper.selectCount(
            new LambdaQueryWrapper<TaskInfo>().eq(TaskInfo::getStatus, "FAILED")
        ));
        
        return vo;
    }
}
